package org.client.chat;

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import org.model.ChatStrings;
import org.model.QParentFrame;

public abstract class ChatingWindow extends QParentFrame{

	protected JTextArea chatArea;
	protected JTextField sendField;
	protected JButton sendButton;
	public ChatingWindow(String text) {
		super(text);
		setWidth(300);
		setHeight(270);
		mainContainer.setLayout(new FlowLayout());
		chatArea = new JTextArea();
		chatArea.setColumns(20);
		chatArea.setRows(10);
		chatArea.setEnabled(false);
		JScrollPane scrollPane = new JScrollPane(chatArea);
		mainContainer.add(scrollPane);
		sendField = new JTextField();
		sendField.setColumns(20);
		mainContainer.add(sendField);
		sendButton = new JButton("Send");
		mainContainer.add(sendButton);
		
		setResizable(false);
		showWindow();
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		addWindowListener(this);
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	protected boolean checkIfEndChat(String line)
	{
		if(line.length() == 3)
		{
			if(line.charAt(0) == 1 && line.charAt(1) == 2 && line.charAt(2) == 3)
			{
				chatArea.append(ChatStrings.END_CHAT);
				chatArea.setCaretPosition(chatArea.getText().length());
				return true;
			}
		}	
		return false;
	}

}
